import java.util.Scanner;

public class MC0422包含1的子串 {
    public static void main(String[] args) {
        //（包含'1'的子串数量） = （总子串数量） - （完全不包含'1'的子串数量）
        //运用公式 n * (n + 1) / 2  等差数列求和公式
        Scanner input = new Scanner(System.in);
        // code here
        int n = input.nextInt();
        input.nextLine();
        String s = input.nextLine();

        //计算总的子串
        long total = (long) n * (n + 1) / 2;

        long zeroOnlySubstrings = 0;
        int consecutiveZeros = 0; // 用于记录当前连续 '0' 的个数

        for (int i = 0; i < n; i++) {
            if (s.charAt(i) == '0') {
                consecutiveZeros++;
            } else {
                // 遇到 '1'结算,之前积累的连续 '0'
                if (consecutiveZeros > 0) {
                    zeroOnlySubstrings += (long) consecutiveZeros * (consecutiveZeros + 1) / 2;
                }
                consecutiveZeros = 0;
            }
        }
        //收尾 ：处理字符串以 '0' 结尾的情况
        if (consecutiveZeros > 0) {
            zeroOnlySubstrings += (long) consecutiveZeros * (consecutiveZeros + 1) / 2;

        }
        long res = total - zeroOnlySubstrings;
        System.out.println(res);
        input.close();
    }
}
